

import prompt from '@system.prompt';

export default {
  data: {
    percent: 0,
    interval: ''
  },
  //点击弹出框，内容可以定义，
  showAlert() {
    this.$element('alertDialog').show();
  },
  showConfirm() {
    this.$element('confirmDialog').show();
  },
  //loading效果
  showLoading() {
    const options = {
      duration: 800,
      easing: 'linear',
      iterations: 'Infinity'
    };
    const frames = [
      {
        transform: {
          rotate: '0deg'
        }
      },
      {
        transform: {
          rotate: '360deg'
        }
      }
    ];
    this.animation = this.$element('loading-img').animate(frames, options);
    this.$element('loadingDialog').show();
    this.animation.play();
  },
  //输入框
  showPrompt() {
    this.$element('promptDialog').show();
  },
  //进度条
  showProgress() {
    const that = this;
    that.percent = 0;
    this.$element('progressDialog').show();
    this.interval = setInterval(function() {
      that.percent += 10;
      if (that.percent >= 100) {
        clearInterval(that.interval);
      }
    }, 500);
  },
  //确定
  confirmClick(id) {
    this.$element(id).close();
    prompt.showToast({
      message: 'confirm clicked'
    });
  },

  //取消
  cancelClick(id) {
    this.$element(id).close();
    prompt.showToast({
      message: 'cancel clicked'
    });
  },
  onCancel(){
    clearInterval(this.interval);
  }
};
